$(function() {
	loadtree() ;
	//weather() ;
}); 

/**
 * 加载树状根
 * @return
 */
function loadtree() {
	$.post("/share/backtree!findTreeRootJson.action?treeform.type=root&d="+new Date().getTime(),null,function(data) {
		var treeMap = eval("("+data+")") ;
	
		var tr_li = $(".ul_navi") ;
		tr_li.empty();
		
		$.each(treeMap.treeRootJson,function(i,n){
			var _li = $("<li>") ;
			_li.attr("id",n.btm_Id) ;
			tr_li.append(_li.text(n.btm_Name)) ;
			
			if(i==0) {
				//默认选中第一个
				_li.css("background","red").css("font-weight","bold");
				printTree(_li.attr("id")) ;
			}
			
			_li.click(function(){
				var cur = $(this) ;
				$(".ul_navi li").css("background","").css("font-weight",""); 
				cur.css("background","red").css("font-weight","bold"); 
				printTree(cur.attr("id")) ;
			});
		}) ;
	}) ;
}

function printTree(treeId) {
	$("#treeboxbox_tree").empty() ;
	
	tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
	tree.setImagePath("../js/dhtmlx/dhtmlxTree/imgs/csh_vista/"); 
	tree.setSkin("dhx_skyblue");
	tree.enableTreeLines(true);
    tree.setImageArrays("plus", "plus2.gif", "plus3.gif", "plus4.gif", "plus.gif", "plus5.gif");
    tree.setImageArrays("minus", "minus2.gif", "minus3.gif", "minus4.gif", "minus.gif", "minus5.gif");
	tree.setStdImages("leaf.gif","folderOpen.gif","folderClosed.gif");	
	tree.loadXML("/share/loadTreeXml?num="+treeId+"&d="+new Date().getTime());
	
	tree.attachEvent("onClick",function(id){   
        if(tree.getUserData(id,"uri") != undefined) {
        	validateURL(tree.getUserData(id,"uri"),"right");
        }
        return true;   
    });   
}

/**
 * 验证权限，超链接方式
 * @param url
 * @return
 */
function validateURL(url,win) {
	$.post("../validateJson!valdateLicence.action?date="+new Date().getTime(),{valUrl:url},function(json) {
		
		var data = eval("("+json+")") ;
		var dataInfo = data.valResult ;
		var ourl = url.indexOf("?")==-1?url+"?d="+new Date().getTime():url+"&d="+new Date().getTime() ;
		window.open(ourl,win) ;  
		if(dataInfo == "true") {
			window.open(ourl,win) ;
		} else if(dataInfo == "login") {
			alert("操作超时，请登录！") ;
			//toolTips("操作超时，请登录",200);
			window.parent.location.href="login.jsp" ;
		} else {
			alert("权限不足，无法使用该操作！") ;
			//toolTips("权限不足，无法使用该操作",200);
		}
	}) ;
}
/**
 * 验证权限，提交按钮方式
 * @param url
 * @return
 */
function valiSub(id) {
	var bto = $("#"+id) ;
	url = bto.attr("action") ;
	
	$.post("validateJson!valdateLicence.action?date="+new Date().getTime(),{valUrl:url},function(json) {
		
		var data = eval("("+json+")") ;
		var dataInfo = data.valResult ;
		
		$("#"+id).submit() ;
		if(dataInfo == "true") {
			$("#"+id).submit() ;
		} else if(dataInfo == "login") {
			alert("操作超时，请登录。") ;
			window.parent.location.href="login.jsp" ;
		} else {
			alert("【权限不足】"+dataInfo);
		}
	}) ;
}

/**
 * 天气预报
 * @return
 */
function weather() {
	var city = $(".city") ;
	var icon = $(".icon") ;
	var info = $(".info") ;
	
	var vals = {city:"广州"} ;
	var url = "../weatherServlet?data="+new Date().getTime() ;
	
	$.ajax({
		url:url,
		data:vals,
		type:"post",
		error:function(a) {
			info.html("<font color=#EEEEEE>暂无法提供天气预报，请连接网络</font>") ;
		},
		success:function(json) {
			var data = eval("("+json+")") ;
			
			if(data.weather != null && data.weather != "#") {
				var infoWeather = data.weather.split("#") ;
				city.html(infoWeather[1]) ;
				icon.html("<img src='../images/weathericon/"+infoWeather[8]+"'\>") ;
				info.html(infoWeather[5] +"&nbsp;"+infoWeather[6].substring(infoWeather[6].indexOf("日")+1)) ;
			} else {
				info.html("<font color=#EEEEEE>[暂无法提供天气预报，请连接网络]</font>") ;
			}
		}
	});
}




